home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tptime.zip / TPTIMER.DOC next >
Text File  |  1988-08-15  |  3KB  |  77 lines

  1. TPTIMER - Routines for high-resolution timing of events
  2. -------------------------------------------------------
  3. Brian Foley and Kim Kokkonen
  4. TurboPower Software
  5. 8/88
  6. Version 2.0
  7. Released to the public domain
  8.  
  9. Overview
  10. ------------------------------------------------------------------------------
  11. One problem commonly faced when trying to run benchmarks on a PC is that, by
  12. default, the system clock is accurate only to 1/18th of a second. The TPTIMER
  13. unit provides a simple and convenient means of timing events with microsecond
  14. resolution. It does this by reprogramming the timer chip, but the gory details
  15. are hidden from you. TPTIMER automatically reprograms the timer before your
  16. program starts, then restores it to its normal state when your program ends.
  17. Unless your program is working with the timer chip at a very low level, no
  18. incompatibilities should arise, nor should the performance of your program
  19. change.
  20.  
  21. Using TPTIMER
  22. ------------------------------------------------------------------------------
  23. TPTIMER is very easy to use. You just add it to your program's USES statement
  24. and call the ReadTimer function when you are ready to start/stop timing. For a
  25. simple demonstration of how to use TPTIMER, see TTDEMO.PAS.
  26.  
  27. TPTIMER interfaces the following routines:
  28.  
  29.   function ReadTimer : LongInt;
  30.     {-Read the timer with 1 microsecond resolution}
  31.  
  32.   function ElapsedTime(Start, Stop : LongInt) : Real;
  33.     {-Calculate time elapsed (in milliseconds) between Start and Stop}
  34.  
  35.   function ElapsedTimeString(Start, Stop : LongInt) : string;
  36.     {-Return time elapsed (in milliseconds) between Start and Stop as a string}
  37.  
  38.   procedure InitializeTimer;
  39.     {-Reprogram the timer chip to allow 1 microsecond resolution}
  40.  
  41.   procedure RestoreTimer;
  42.     {-Restore the timer chip to its normal state}
  43.  
  44. The first three of these are probably the only ones you'll ever need to use.
  45. InitializeTimer is executed automatically before your program begins,
  46. RestoreTimer when it ends. You shouldn't call these yourself unless you want
  47. to reset the timer to its normal state temporarily, as you might before using
  48. the Exec procedure in the DOS unit:
  49.  
  50.    RestoreTimer;
  51.    Exec();
  52.    InitializeTimer;
  53.  
  54. Limitations
  55. -----------
  56. Because long integers are used to represent time, TPTIMER cannot be used to
  57. time events longer than about 60 minutes:
  58.  
  59.    4,294,967,295 (= $FFFFFFFF, largest unsigned value represented by longint)
  60.  /     1,193,181 (timer resolution in counts/second)
  61.  ---------------
  62.            3,599
  63.          /    60 (seconds/minute)
  64.          -------
  65.             59.9 minutes
  66.  
  67. This should hardly be a problem, however, since an event longer than an hour
  68. presumably doesn't need to be timed with 1-microsecond accuracy anyway.
  69.  
  70. Also note that the process of reading the time takes time. Hence, results of
  71. timing very short events will be skewed by the overhead of reading the timer.
  72. As of version 2.0, TPTIMER executes a calibration routine to try to compensate
  73. for this overhead as much as possible. This routine estimates the amount of
  74. time required to read the timer twice, and uses this value in ElapsedTime and
  75. ElapsedTimeString to adjust for the overhead. Even so, you should expect an
  76. error due to overhead of about 1-4 ms.
  77.